<?php
namespace app\SuperAdmin\controller;

use app\SuperAdmin\model\AdminModel;
use think\Controller;
use think\Session;

class AdminController extends Controller
{
    public function _initialize()
    {
        if (!Session::has('adminid'))
        {
            $this->redirect('index/index/index');
        }
    }


    public function index()
    {
        return $this->fetch();
    }

    public function editpass()
    {
        return $this->fetch();
    }

    public function logout()
    {
        Session::clear();
        $this->redirect('index/index/index');
    }

    public function confirm_editpass()
    {
        $admin=AdminModel::get(Session::get('adminid'));
        if($admin->adminpwd==input('oldPassword'))
        {
            $admin->adminpwd=input('newPassword');
            $admin->save();
            $this->success('修改成功');
        }
        else
        {
            $this->error('修改失败，与原密码不符');
        }
    }
}